package GUI;

import java.awt.*;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JPanel;
import Messages.MessageShowAllSuppliers;
import Messages.MessageShowAllSuppliersReply;
import Messages.MessageShowIDSupplier;
import Messages.MessageShowSupplierIDReply;

public class PanelFunctionsSuppliers extends PanelFunctionsEmpty 
{
	private MainMenu mainMenu;
	private JButton button_addSupplier;
	private JButton button_findSupplier;
	
public PanelFunctionsSuppliers(MainMenu mm )
{
	super(mm);
	this.mainMenu=mm;
	this.add(get_button_addSupplier());
	this.add(get_button_findSupplier());
}
	
	
	
	
private JButton get_button_addSupplier() 
	{
		if (button_addSupplier == null) 
		{			
			button_addSupplier=new JButton("הוספת ספק");  			 
			button_addSupplier.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_addSupplier.setPreferredSize(new Dimension(220, 30));
			
			button_addSupplier.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
             MessageShowIDSupplier msgShowID=new MessageShowIDSupplier( );
				
				
				try {
					mainMenu.ms.client.sendToServer(msgShowID);
					MessageShowSupplierIDReply resultID=(MessageShowSupplierIDReply)mainMenu.ms.client.GetMessage();
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfAdd_new_supplier(mainMenu,resultID.getResultID()), BorderLayout.CENTER);							
					mainMenu.getContentPane().validate();
					
					
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				
				}		
				
				
			});
		}
		return button_addSupplier;
	}
	
	
	
	

	
private JButton get_button_findSupplier() 
{
	if (button_findSupplier == null) 
	{			
		button_findSupplier=new JButton("חיפוש ספק");  			 
		button_findSupplier.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_findSupplier.setPreferredSize(new Dimension(220, 30));
		
		button_findSupplier.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				
				MessageShowAllSuppliers msgShowSupp=new MessageShowAllSuppliers( );
				try {
					mainMenu.ms.client.sendToServer(msgShowSupp);
					MessageShowAllSuppliersReply resultSupp=(MessageShowAllSuppliersReply)mainMenu.ms.client.GetMessage();
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.EAST));
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfSearch_supplier(mainMenu,resultSupp.getResult()), BorderLayout.CENTER);	
					mainMenu.getContentPane().add(new PanelFunctionsSuppliers(mainMenu), BorderLayout.EAST);
					mainMenu.getContentPane().validate();
				}
				catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
									
			}
		});
	}
	return button_findSupplier;
}
}